<#-- 导入模版定义文件-->
<#include "../template/template_editPage.ftl">
<@edit title="商品信息管理">
    <#if (goodsId)??>
        <#assign isEdit = true />
    <#else>
        <#assign isAdd = true />
    </#if>
<body class="input">

<script type="text/javascript">


    $().ready(function () {

        var $validateErrorContainer = $("#validateErrorContainer");
        var $validateErrorLabelContainer = $("#validateErrorContainer ul");
        var $validateForm = $("#inputForm");
        var $tab = $("#tab");

        // Tab效果
        $tab.tabs(".tabContent", {
            tabs:"input"
        });

        // 表单验证
        $validateForm.validate({
            errorContainer:$validateErrorContainer,
            errorLabelContainer:$validateErrorLabelContainer,
            wrapper:"li",
            errorClass:"validateError",
            ignoreTitle:true,
            rules:{
                "goods.goodsId":{
                    required:true
                },
                "goods.goodsCategoryId":{
                    required:true
                },
                "goods.goodsName":{
                    required:true
                },
                "goods.brandName":{
                    required:true
                },
                "commonSalePrice":{
                    required:true
                },
                "goodsMoney":{
                    required:true
                },
                "goods.rechargeMode":{
                    required:true
                },
                "goods.enable":{
                    required:true
                }
            },
            messages:{
                "goods.goodsId":{
                    required:"商品编号不能为空！"
                },
                "goods.goodsCategoryId":{
                    required:"商品品牌不能为空！"
                },
                "goods.goodsName":{
                    required:"请填写商品名称！"
                },
                "goods.brandName":{
                    required:"请填写品牌名称！"
                },
                "commonSalePrice":{
                    required:"商品默认售价不能为空！"
                },
                "goodsMoney":{
                    required:"商品面值不能为空！"
                },
                "goods.rechargeMode":{
                    required:"请选择商品充值方式！"
                },
                "goods.enable":{
                    required:"请选择是否启用！"
                }
            },
            submitHandler:function (form) {
                //$(form).find(":submit").attr("disabled", true);
                form.submit();
            }
        });
        <#if actionErrors?? && (actionErrors?size > 0)>
            $.messager.show("提示信息", "<#list errorMessages as list>${list}<br></#list>", 2000);
        </#if>
    });
    function checkPrice() {
        $("#priceSpan").html('');
        var e = /^(([1-9]\d*)|\d)(\.\d{1,3})?$/;
        var blsx = $("#commonSalePrice").val();
        if (!e.test(blsx)) {
            $("#priceSpan").html('价格格式不正确！(例：0.000)');
            return false;
        }
        else {
            return true;
        }
    }

    function checkParvalue() {
        $("#priceSpan2").html('');
        var e = /^(([1-9]\d*)|\d)(\.\d{1,3})?$/;
        var blsx = $("#goodsMoney").val();
        if (!e.test(blsx)) {
            $("#priceSpan2").html('价格格式不正确！(例：0.000)');
            return false;
        }
        else {
            return true;
        }
    }
</script>

<div class="body">
<div class="inputBar">
    <h1><span class="icon">&nbsp;</span><#if isAdd??>添加商品信息<#else>编辑商品信息</#if></h1>
</div>
<div style="display: none;" id="validateErrorContainer" class="validateErrorContainer">
    <div class="validateErrorTitle">以下信息填写有误,请重新填写</div>
    <ul></ul>
</div>
<form id="inputForm" class="validate"
      action="<#if isAdd??>${web_base}/game/goods!save.htm<#else>${web_base}/game/goods!edit.htm</#if>"
      method="post">
    <input type="hidden" name="goId" value="${goId!}">
    <input type="hidden" name="brandId" value="${brandId!}">
    <input type="hidden" name="goodsName" value="${goodsName!}">
    <input type="hidden" name="rechargeMode" value="${rechargeMode!}">
    <ul class="tab">
        <li>
            <input type="button" value="基本信息" hidefocus="true"/>
        </li>
    </ul>
    <input type="hidden" name="goods.id" class="formText" value="${(goods.id)!}"/>
    <table class="inputTable tabContent">
        <#if !isAdd??>
            <tr>
                <th>
                    商品编号：
                </th>
                <td>
                    <input type="text" name="goods.goodsId" class="formText {required: true}"
                           value="${(goods.goodsId)!}"/>
                </td>
            </tr>
        </#if>

        <tr>
            <th>
                商品名称：
            </th>
            <td>
                <#if isAdd??>
                    <input type="text" name="goods.goodsName" class="formText {required: true}"
                           value="${(goods.goodsName)!}"/>
                    <label class="requireField">*</label>
                <#else>
                    <input type="text" name="goods.goodsName" class="formText {required: true}"
                           value="${(goods.goodsName)!}"/>
                </#if>
            </td>
        </tr>
        <tr>
            <th>
                品牌名称：
            </th>
            <td>
                <select name="goods.goodsCategoryId" class="formText {required: true}">
                    <option value="">请选择...</option>
                    <#if brandList??>
                        <#list brandList as obj>
                            <option value="${obj.goodsCategoryId!}" <#if goods?? && obj.goodsCategoryId == goods.goodsCategoryId>selected</#if>>
	                           <#if obj.gameName?? && obj.gameName?length gte 15>
		                                <#--//截取输出文字的长度-->
		                                ${obj.gameName?substring(0,15)}...
		                            <#else>
		                                ${(obj.gameName)!}
		                            </#if>
                            </option>
                        </#list>
                    </#if>
                </select>
                <label class="requireField">*</label>
            </td>
        </tr>
        <tr>
            <th>
                默认售价(元)：
            </th>
            <td>
                <#if isAdd??>
                    <input type="text" id="commonSalePrice" name="commonSalePrice" class="formText {required: true}"
                           value="" onblur="checkPrice()"/>
                <#else>
                    <input type="text" id="commonSalePrice" name="commonSalePrice" class="formText {required: true}"
                           value="${(goods.commonSalePrice*1.0/1000)?string("0.000")}" onblur="checkPrice()"/>
                </#if>
                <label class="requireField">*</label>
                <span id="priceSpan" style="color: red;"></span>
            </td>
        </tr>

        <tr>
            <th>
                商品面值(元)：
            </th>
            <td>

                <#if isAdd??>
                    <input type="text" id="goodsMoney" name="goodsMoney" class="formText {required: true}"
                           value="" onblur="checkParvalue()"/>
                <#else>

                    <input type="text" id="goodsMoney" name="goodsMoney" class="formText {required: true}"
                           value="${(goods.goodsMoney*1.0/1000)?string("0.000")}" onblur="checkParvalue()"/>
                </#if>
                <label class="requireField">*</label>
                <span id="priceSpan2" style="color: red;"></span>
            </td>
        </tr>

        <tr>
        <th>
            热度选择：
        </th>
        <td>
            <#if !isAdd??>
                <select name="goods.heat" class="formText {required: true}">
                    <option value="">请选择...</option>
                    <option value=2 <#if goods?? && goods.heat?? && goods.heat==2>selected="selected"</#if>>
                        热门
                    <option value=1 <#if goods??  && goods.heat?? && goods.heat==1>selected="selected"</#if>>
                       一般
                    </option>
                </select>
            <#else>
                <select name="goods.heat" class="formText {required: true}">
                    <option value=1>请选择...</option>
                    <option value=2>
                        热门
                    <option value=1>
                        一般
                    </option>
                </select>
            </#if>
        </td>
    </tr>
        <tr>
            <th>
                充值方式：
            </th>
            <td>
                <#if !isAdd??>
                    <select name="goods.rechargeMode" class="formText {required: true}">
                        <option value="">请选择...</option>
                        <option value="2" <#if goods?? && goods.rechargeMode=="2">selected="selected"</#if>>
                            直充
                        </option>
                        <option value="1" <#if goods?? && goods.rechargeMode=="1">selected="selected"</#if>>
                            卡充
                        </option>
                    </select>
                <#else>
                    <select name="goods.rechargeMode" class="formText {required: true}">
                        <option value="" selected="selected">请选择...</option>
                        <option value="2">
                            直充
                        </option>
                        <option value="1">
                            卡充
                        </option>
                    </select>
                </#if>
                <label class="requireField">*</label>
            </td>
        </tr>
        <tr>
            <th>
                是否启用：
            </th>
            <td>
                <#if !isAdd??>
                    <select name="goods.enable" class="formText {required: true}">
                        <option value="">请选择...</option>
                        <option value="1" <#if goods.enable=="1">selected="selected"</#if>>
                            启用
                        </option>
                        <option value="0" <#if goods.enable=="0">selected="selected"</#if>>
                            禁用
                        </option>
                    </select>
                <#else>
                    <select name="goods.enable" class="formText {required: true}">
                        <option value="" selected="selected">请选择...</option>
                        <option value="1">
                            启用
                        </option>
                        <option value="0">
                            禁用
                        </option>
                    </select>
                </#if>
                <label class="requireField">*</label>
            </td>
        </tr>
        <tr>
            <th>
                可充值数量：
            </th>
            <td>
                <input type="text" name="goods.numLimit" class="formText {required: false}"
                       value="${(goods.numLimit)!}"/>
            </td>
        </tr>
        <tr>
            <th>
                商品描述：
            </th>
            <td>
                <textarea name="goods.goodsDescription" class="formTextarea">${(goods.goodsDescription)!}</textarea>
            </td>
        </tr>
        <tr>
            <th>
                游戏说明：
            </th>
            <td>
                <textarea name="goods.stateMent" class="formTextarea">${(goods.stateMent)!}</textarea>
            </td>
        </tr>
        <tr>
            <th>
                备注：
            </th>
            <td>
                <textarea name="goods.remark" class="formTextarea">${(goods.remark)!}</textarea>
            </td>
        </tr>
    </table>
    <div class="buttonArea">
        <input type="submit" class="formButton" <#if isAdd??> value="添  加" <#else> value="更  新"</#if>hidefocus="true" />&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="button" class="formButton" onclick="window.history.back(); return false;" value="返  回"
               hidefocus="true"/>
    </div>
</form>
</div>
</body>
</@edit>
